cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _reconnect:null,
        _lblTip:null,
        _lastPing:0,
    },

    // use this for initialization
    onLoad: function () {
        this._reconnect = cc.find("Canvas/reconnect");
        this._lblTip = cc.find("Canvas/reconnect/tip").getComponent(cc.Label);
        var self = this;
        
        var fnTestServerOn = function(){
            console.log("重连中...")
            cc.vv.net.test(function(ret){
               if(ret){
                    console.log("重连成功...");
                    // 清除最新所在俱乐部数据防止影响游戏重连
                    cc.vv.userMgr.nowClubData=null;
                    
                    cc.director.loadScene('mjhall');
                    //重连不切场景
                    // cc.vv.gameNetMgr.isReconnect=true;
                    // cc.vv.userMgr.enterRoom(cc.vv.userMgr.oldRoomId);
                    // cc.vv.gameNetMgr.connectGameServer(cc.vv.gameNetMgr.connectRet);
                    // 重连开启俱乐部ws
                    cc.vv.userMgr.connectClubServer()             
               }else{
                    setTimeout(fnTestServerOn,2000);
                    console.log("重连失败..");
               }
            });
        }
        
        var fn = function(data){
            console.log("websocket执行重连  recconect start");
            self.node.off('disconnect',fn);
            self._reconnect.active = true;
            fnTestServerOn();
        };
        console.log("adasfdasdfsdf");
        this.node.on('disconnect',fn);
        cc.vv.net.isReconnectOk=true;//节点监听ok
        // this.node.on('reconnectInit',function(data){
        //     console.log("reconnectInit/recconect",data.detail);
        //     self._reconnect.active=false
        // })
    },
    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        if(this._reconnect.active){
            var t = Math.floor(Date.now() / 1000) % 4;
            this._lblTip.string = "与服务器断开连接，正在尝试重连";
            // cc.find("Canvas/prepare/btnReady").active = !cc.vv.seat._ready;
            for(var i = 0; i < t; ++ i){
                this._lblTip.string += '.';
            }
        }
    },
});
